package com.augurit.gzcgwsp.rqqyjyxk.web;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.web.struts2.Struts2Utils;

import com.augurit.common.base.action.ExtCrudActionSupport;
import com.augurit.common.util.ExtUtils;
import com.augurit.common.util.lang.DateUtils;
import com.augurit.common.util.lang.StringUtils;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkRqjszdjb;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkRqqxssdjb;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalRqjszdjb;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalRqqxssdjb;
import com.augurit.gzcgwsp.rqqyjyxk.service.IYwRqQyjyxkFinalRqjszdjbService;
import com.augurit.gzcgwsp.rqqyjyxk.service.IYwRqQyjyxkFinalRqqxsbylbService;
import com.augurit.gzcgwsp.rqqyjyxk.service.IYwRqQyjyxkService;
import com.augurit.gzcgwsp.rqqyjyxk.web.form.YwRqQyjyxkForm;
import com.augurit.gzcgwsp.rqqyjyxk.web.form.YwRqQyjyxkSsylbForm;

@SuppressWarnings("serial")
@Results({
	@Result(name = "dataInfo", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/otherInfo/rqssjscpjqz.jsp"),

		
})

/**
 * 燃气接收站、储配站、汽车加气站 登记
 */
public class YwRqQyjyxkJscpjqzAction extends ExtCrudActionSupport{
	@Autowired
	private IYwRqQyjyxkFinalRqjszdjbService ywRqQyjyxkFinalRqjszdjbService;
	@Autowired
	private IYwRqQyjyxkService ywRqQyjyxkService;
	private Page page = new Page(10);

	@Override
	public String delete() throws Exception {
		String id=getRequest().getParameter("sslybid");
		String type=getRequest().getParameter("type");
		//ywRqQyjyxkSsylbService.doDelete(id,type);
		return null;
	}
	@Override
	public String execute() throws Exception {
		return this.getInfo();
	}
    
	/**
	 * 到燃气接收站、储配站、汽车加气站 首页
	 * @return
	 */
	private String getInfo() {
		String acceptNo=getRequest().getParameter("acceptNo");
		String qyid=getRequest().getParameter("qyid");
		getRequest().setAttribute("acceptNo", acceptNo);
		getRequest().setAttribute("qyid", qyid);
		return "dataInfo";
	}


	/**
	 * 分页查询抢险点
	 * @return
	 * @throws Exception
	 */
	public String getDatas() throws Exception {
		String acceptNo=getRequest().getParameter("acceptNo");
		String qyid=getRequest().getParameter("qyid");
		String type=getRequest().getParameter("type");
	    if(page==null){
	  		  page = new Page(10);
	  	 }
	    ExtUtils.initPageFromExtGridParam(getRequest(), page);
	    
	    if(StringUtils.isNotBlank(acceptNo)){
	    	 page=ywRqQyjyxkFinalRqjszdjbService.getPage(acceptNo,page,null,"");
	    	 renderText(Struts2Utils.getJsonString(page, DateUtils.YYYY_MM_DD_HH_MM_SS));
	    }
	    if(StringUtils.isNotBlank(qyid)){
	    	 page=ywRqQyjyxkFinalRqjszdjbService.getPage("",page,Long.valueOf(qyid),type);
	    	renderText(Struts2Utils.getJsonString(page, DateUtils.YYYY_MM_DD_HH_MM_SS));
	    }
	  
		return null;
	}


	public String save() throws Exception {
		Map  map=getMapByRequest(getRequest());
		boolean flag=false;//ywRqQyjyxkSsylbService.saveEntity(map);
		if(flag)
			getResponse().getWriter().print("{success:true,msg:'true'}");
		else
			getResponse().getWriter().print("{success:true,msg:'false'}");
		return null;
	}
	
	public String doUpdate() throws Exception {
		String type=this.getRequest().getParameter("type");
		Map  map=getMapByRequest(getRequest());
		boolean flag=false;//ywRqQyjyxkSsylbService.saveEntity(map);
		if(flag)
			getResponse().getWriter().print("{success:true,msg:'true'}");
		else
			getResponse().getWriter().print("{success:true,msg:'false'}");
		return null;
	}
	
	
	public String toUpdate() throws Exception{
		String sslybid=getRequest().getParameter("sslybid");
		String type=getRequest().getParameter("type");
		YwRqQyjyxkSsylbForm form=null;
		if("2".equals(type)){
			 form=null;//ywRqQyjyxkSsylbService.getFinalForm(sslybid);
		}else{
			 form=null;//ywRqQyjyxkSsylbService.getForm(sslybid);
		}
		
		JSONObject jsonObject = JSONObject.fromObject(form);
		String data=jsonObject.toString();
		getResponse().getWriter().print("{success: true, data:"+data+"}");
		//extRenderFormJson(form);
		return null;
	}



	public YwRqQyjyxkForm getModel() {
		// TODO Auto-generated method stub
		return null;
	}
    //获取request对象中所有参数，并设置到map中
    private  Map getMapByRequest(HttpServletRequest request) {
        Map<String, String> map = new HashMap<String, String>();
        Enumeration enu = request.getParameterNames();
        while(enu.hasMoreElements()) {   
            String paraName = (String)enu.nextElement();   
            String paraValue = request.getParameter(paraName).trim(); 
            if(paraValue!=null && !"".equals(paraValue)){
                map.put(paraName, paraValue);
            }
        }  
        return map;
    }


	@Override
	protected void prepareModel() throws Exception {
		// TODO Auto-generated method stub
		
	}


	@Override
	public String list() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

    
}
